﻿namespace Codeblack.TfsScrumboard.Runtime
{
    using System.Web;
    using Codeblack.TfsScrumboard.Interfaces;
    using Codeblack.TfsScrumboard.Services;
    using Microsoft.Practices.Unity;
    using Codeblack.TfsScrumboard.Repositories;

    /// <summary>
    /// Creates the singleton unity-container and registers any services used by this application.
    /// </summary>
    public class UnityContainerModule : IHttpModule
    {
        #region IHttpModule implementation

        /// <summary>
        /// Initializes this module and prepares it to handle requests.
        /// </summary>
        /// <param name="context">An System.Web.HttpApplication that provides access to the methods, properties,
        /// and events common to all application objects within an ASP.NET application</param>
        public void Init(HttpApplication context)
        {
            IUnityContainer unityContainer = new UnityContainer();

            unityContainer.RegisterType<IScrumboardService, ScrumboardService>();
            unityContainer.RegisterType<ITeamFoundationRepository, TeamFoundationRepository>();
            unityContainer.RegisterType<IScrumboardSettings, ScrumboardSettings>();

            Container.Initialize(unityContainer);
        }

        /// <summary>
        /// Disposes of the resources (other than memory) used by the module that implements System.Web.IHttpModule.
        /// </summary>
        public void Dispose()
        {
        }

        #endregion
    }
}
